﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;
using Microsoft.WindowsMobile.PocketOutlook;

namespace SmartDeviceFileAsMe
{
    public partial class frmMain : Form
    {
        private ChooseContactDialog ccd;

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            panel1.Visible = false;
            tbNewString.Text = "";
            tbOldString.Text = "";
            btnUpdate.Enabled = false;
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            ccd = new ChooseContactDialog();
            DialogResult result = ccd.ShowDialog();

            if (result == DialogResult.OK)
            {
                panel1.Visible = true;
                tbOldString.Text = ccd.SelectedContact.FileAs.ToString();
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ccd.SelectedContact.FileAs = tbNewString.Text.Trim();
            try
            {
                ccd.SelectedContact.Update();
                MessageBox.Show("Update Successful!", "Result", MessageBoxButtons.OK,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
                panel1.Visible = false;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tbNewString_TextChanged(object sender, EventArgs e)
        {
            if (tbNewString.Text == "")
            {
                btnUpdate.Enabled = false;
            }
            else
            {
                btnUpdate.Enabled = true;
            }
        }
    }
}